package main

import (
	"fmt"
    "strings"
    "unicode"
)

func main() {
	// Get input from the user
	var input string
	fmt.Print("Enter a string to check if it's a palindrome: ")
	fmt.Scanln(&input)

	// Call the IsPalindrome function and print the result
	result := IsPalindrome(input)
	if result {
		fmt.Println("The string is a palindrome.")
	} else {
		fmt.Println("The string is not a palindrome.")
	}
}

func cleanString(s string) string {
    var builder strings.Builder
    for _, r := range s {
        if unicode.IsLetter(r) || unicode.IsNumber(r) {
            builder.WriteRune(unicode.ToLower(r))
        }
    }
    return builder.String()
}

// IsPalindrome checks if a string is a palindrome.
// A palindrome reads the same backward as forward, ignoring case, spaces, and punctuation.
func IsPalindrome(s string) bool {
	// TODO: Implement this function
	// 1. Clean the string (remove spaces, punctuation, and convert to lowercase)
	// 2. Check if the cleaned string is the same forwards and backwards
	
	s = cleanString(s)
	if len(s) <= 1{
	    return true
	}
	if s[0] != s[len(s)-1]{
	    return false
	}
	return IsPalindrome(s[1:len(s)-1])
}
